////we should put Elusive and VuVce here instead
/*************************************************************************************
CODED BY:                                                                            *
                                                                                     *
888888b.   8888888888        d8888 888b    888 8888888888P 8888888888 8888888b.      *
888  "88b  888              d88888 8888b   888       d88P  888        888   Y88b     *
888  .88P  888             d88P888 88888b  888      d88P   888        888    888     *
8888888K.  8888888        d88P 888 888Y88b 888     d88P    8888888    888   d88P     *
888  "Y88b 888           d88P  888 888 Y88b888    d88P     888        8888888P"      *
888    888 888          d88P   888 888  Y88888   d88P      888        888 T88b       *
888   d88P 888         d8888888888 888   Y8888  d88P       888        888  T88b      *
8888888P"  8888888888 d88P     888 888    Y888 d8888888888 8888888888 888   T88b     *
                                                                                     *
*************************************************************************************/


#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <unistd.h>
#include <cmath>
#include <cstdlib>

#define ESCAPE 27

int window;
float rtri = 0.0f;
float rquad = 0.0f;
bool* keyStates  = new bool[256];
float depth = -10.0f,Movex = 0.0f, Movey = 0.0f;
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0;
float positionz[10];
float positionx[10];


void InitGL(int Width, int Height)
{
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClearDepth(1.0);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glShadeModel(GL_SMOOTH);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
  glMatrixMode(GL_MODELVIEW);

}

void camera (void) {
    glRotatef(xrot,1.0,0.0,0.0);
    glRotatef(yrot,0.0,1.0,0.0);
    glTranslated(-xpos,-ypos,-zpos);
}

void ReSizeGLScene(int Width, int Height)
{
  if (Height==0)
    Height=1;

  glViewport(0, 0, Width, Height);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
  glMatrixMode(GL_MODELVIEW);
}

void DrawGLScene()
{


  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  glLoadIdentity();

  glTranslatef(Movex,Movey,depth);		// Move Left 1.5 Units And Into The Screen 6.0

camera();

angle++;

  glRotatef(rtri,0.0f,1.0f,0.0f);		// Rotate The Pyramid On The Y axis
   //glutWireCube(2.0f);
  glBegin(GL_POLYGON);

  // front
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f(0.0f, 1.0f, 0.0f);
  glColor3f(0.0f,1.0f,0.0f);
  glVertex3f(-1.0f,-1.0f, 1.0f);
  glColor3f(0.0f,0.0f,1.0f);
  glVertex3f(1.0f,-1.0f, 1.0f);

  // right
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.0f,0.0f,1.0f);
  glVertex3f( 1.0f,-1.0f, 1.0f);
  glColor3f(0.0f,1.0f,0.0f);
  glVertex3f( 1.0f,-1.0f, -1.0f);

  // back
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.0f,1.0f,0.0f);
  glVertex3f( 1.0f,-1.0f, -1.0f);
  glColor3f(0.0f,0.0f,1.0f);
  glVertex3f(-1.0f,-1.0f, -1.0f);

  // left
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.0f,0.0f,1.0f);
  glVertex3f(-1.0f,-1.0f,-1.0f);
  glColor3f(0.0f,1.0f,0.0f);
  glVertex3f(-1.0f,-1.0f, 1.0f);

  glEnd();
//////////////////////////////////////////////////////
  //glLoadIdentity();
  //glTranslatef(0.0f,0.0f,-7.0f);

 // glRotatef(rquad,1.0f,1.0f,1.0f);		for the cubera


  /*damn cube thingy
  glBegin(GL_QUADS);

  // top of the cube
  glColor3f(0.0f,1.0f,0.0f);
  glVertex3f( 1.0f, 1.0f,-1.0f);
  glVertex3f(-1.0f, 1.0f,-1.0f);
  glVertex3f(-1.0f, 1.0f, 1.0f);
  glVertex3f( 1.0f, 1.0f, 1.0f);

  // bottom of the cube
  glColor3f(1.0f,0.5f,0.0f);
  glVertex3f( 1.0f,-1.0f, 1.0f);
  glVertex3f(-1.0f,-1.0f, 1.0f);
  glVertex3f(-1.0f,-1.0f,-1.0f);
  glVertex3f( 1.0f,-1.0f,-1.0f);

  // front of the cube
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f( 1.0f, 1.0f, 1.0f);
  glVertex3f(-1.0f, 1.0f, 1.0f);
  glVertex3f(-1.0f,-1.0f, 1.0f);
  glVertex3f( 1.0f,-1.0f, 1.0f);

  // back ofthe cube.
  glColor3f(1.0f,1.0f,0.0f);
  glVertex3f( 1.0f,-1.0f,-1.0f);
  glVertex3f(-1.0f,-1.0f,-1.0f);
  glVertex3f(-1.0f, 1.0f,-1.0f);
  glVertex3f( 1.0f, 1.0f,-1.0f);

  // left of the cube
  glColor3f(0.0f,0.0f,1.0f);
  glVertex3f(-1.0f, 1.0f, 1.0f);
  glVertex3f(-1.0f, 1.0f,-1.0f);
  glVertex3f(-1.0f,-1.0f,-1.0f);
  glVertex3f(-1.0f,-1.0f, 1.0f);

  // Right of the cube
  glColor3f(1.0f,0.0f,1.0f);
  glVertex3f( 1.0f, 1.0f,-1.0f);
  glVertex3f( 1.0f, 1.0f, 1.0f);
  glVertex3f( 1.0f,-1.0f, 1.0f);
  glVertex3f( 1.0f,-1.0f,-1.0f);
  glEnd();	*/

  rtri+=0.07f;
  //rquad-=0.2f;

  glutSwapBuffers();

}


void keyPressed(unsigned char key, int x, int y)
{
keyStates[key] = true;
    usleep(100);

    if (key == ESCAPE)
    {
      glutDestroyWindow(window);
      exit(0);
    }
     if (key=='q')
    {
    xrot += 1;
    if (xrot >360) xrot -= 360;
    }

    if (key=='e')
    {
    xrot -= 1;
    if (xrot < -360) xrot += 360;
    }

    if (key=='w')
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos += float(sin(yrotrad)) ;
    zpos -= float(cos(yrotrad)) ;
    ypos -= float(sin(xrotrad)) ;
    }

    if (key=='s')///////////////////////////////mess with this later
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos -= float(sin(yrotrad));
    zpos += float(cos(yrotrad)) ;
    ypos += float(sin(xrotrad));
    }

    if (key=='d')
    {
    yrot += 1;
    if (yrot >360) yrot -= 360;
    }

    if (key=='a')
    {
    yrot -= 1;
    if (yrot < -360)yrot += 360;
    }
}

void keyUp (unsigned char key, int x, int y)/////when like the key is unpressed
{
   keyStates[key] = false;
}


void keyspecial(int key, int x, int y)
{

    if (key == GLUT_KEY_UP)
        {
            Movey += 0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_DOWN)
        {
            Movey += -0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_LEFT)
        {
            Movex += -0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_RIGHT)
        {
            Movex += 0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_PAGE_UP)
        {
            depth += 0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_PAGE_DOWN)
        {
            depth += -0.5f;
            glutPostRedisplay();
        }
}

void specialKeyUp (unsigned char key, int x, int y)
    {
        keyStates[key] = false;
    }


int main(int argc, char **argv)
{

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
  glutInitWindowSize(640, 480);
  glutInitWindowPosition(0, 0);
  window = glutCreateWindow("Sector7 beanzer Test");
  glutDisplayFunc(&DrawGLScene);
  glutFullScreen();
  glutIdleFunc(&DrawGLScene);
  glutReshapeFunc(&ReSizeGLScene);
  glutKeyboardFunc(&keyPressed);
  glutKeyboardUpFunc(&keyUp);
  glutSpecialFunc(&keyspecial);
  glutKeyboardUpFunc(&specialKeyUp);
  InitGL(640, 480);
  glutMainLoop();

  return 1;
}



